import { Currency } from '@/types/currency';

function getCurrencyInfo(coin: string) {
  let info = {
    name: 'ETH',
    fullname: '',
    desc: '',
    power: -3,
    unit: 'MH/s',
    power_web: -3,
    power_monitor: -6,
  };

  return info;
}

export default function formatHash(
  hash: number,
  type = 'ETH',
  info: Currency | undefined,
  pow = true,
) {
  if (type === '' || !type) {
    return '无';
  }

  if (!info) {
    info = getCurrencyInfo(type);
  }

  if (hash <= 0) {
    return `0.00 ${info.unit}`;
  }

  let v = hash * (pow ? Math.pow(10, info.power_web) : 1);
  return v > 999.999999 && info.unit === 'MH/s'
    ? (v / 1000.0).toFixed(1) + ' ' + 'GH/s'
    : v.toFixed(1) + ' ' + info.unit;
}
